package com.tanhua.app.controller;


import com.tanhua.app.service.UserService;
import com.tanhua.domain.db.User;

import com.tanhua.domain.db.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    //根据用户手机号查询  get 方式
    @GetMapping(value = "/findByPhone",name = "根据用户手机号查询 ")
    public ResponseEntity findByPhone(String phone){
        return userService.findByPhone(phone);

    }
    //保存用户  用post  请求
    @PostMapping(value = "/saveUser", name="保存用户")
    public ResponseEntity saveUser (User user){
        return userService.saveUser(user);

    }
    //用户登入注册
    @PostMapping(value = "/loginVerification", name ="用户登入注册" )
  public ResponseEntity loginVerification(@RequestBody Map param){
            String phone= (String) param.get("phone");
            String vCode= (String) param.get("verificationCode");
        return userService.loginVerification(phone,vCode);
    }
    //发送验证码
    @PostMapping(value = "/login",name = "发送短信验证码")
    public ResponseEntity login(@RequestBody Map param){
        String phone= (String) param.get("phone");
        return userService.login(phone);

    }
    //完善基本信息
    @PostMapping(value = "/loginReginfo", name = "完善基本信息")
     public ResponseEntity loginReginfo(@RequestBody UserInfo userInfo,
                                        @RequestHeader("Authorization" )String token) {

                    userService.logininfo(userInfo,token);
                     return ResponseEntity.ok(null);
    }
    // 完善头像信息
    @PostMapping(value = "/loginReginfo/head",name ="完善头像信息")
    public ResponseEntity loginReginfoPic(MultipartFile headPhoto, @RequestHeader("Authorization") String  token) throws Exception{
        return userService.loginReginfoPic(headPhoto ,token);
    }



}
